package cn.kn.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * @author WangJiang
 * @create 2020-12-05 10:22
 */
public class CopyBean {
    public static <S,T> T copyBean(S source, Supplier<T> target){
        T t=target.get();
        BeanUtils.copyProperties(source,t);
        return t;
    }

    public static <S,T> List<T> copyBean(List<S> sources,Supplier<T> target){
       return sources
               .stream()
               .map(s ->copyBean(s,target))
               .collect(Collectors.toList());
    }
}
